/**============================================================================
 *
 * Author: luo1o1o1o 
 *
 * QQ: 330240995, PHONE: 17600071321
 *
 * Last modified: 2021-06-09 09:51
 *
 * Filename: user.js
 *
 * Description: 数据格式校验
 *
 ============================================================================**/
const validate = require('./_validate')
// 校验规则
const SCHEMA = {
    type: 'object',
    properties: {
        userName: {
            type: 'string',
            pattern: '^[a-zA-Z][a-zA-Z0-9_]+$', // 字母开头，字母数字下划线
            maxLength: 255,
            minLength: 2,
        },
        password: {
            type: 'string',
            maxLength: 255,
            minLength: 3,
        },
        newPassword: {
            type: 'string',
            maxLength: 255,
            minLength: 3,
        },
        nickName: {
            type: 'string',
            maxLength: 255,
        },
        picture: {
            type: 'string',
            maxLength: 255,
        },
        city: {
            type: 'string',
            maxLength: 255,
            minLength: 2,
        },
        gender: {
            type: 'number',
            minimum: 1,
            maximum: 3,
        },
    },
}

/**
 * @Author: luo1o1o1o
 * @QQ: 330240995, @PHONE: 17600071321
 * @Date: 2021-06-09 11:19
 * @desc: 校验用户数据格式
 */
function userValidate(data = {}) {
    return validate(SCHEMA, data)
}

module.exports = userValidate
